package com.potenza.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class KafkaProducer {

    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;

    // 发送消息
    @GetMapping("/kafka/normal/{message}")
    public void sendMessage1(@PathVariable("message") String normalMessage) {
        System.out.println(normalMessage);
        kafkaTemplate.send("testtopic_1905A", normalMessage);
    }

    @RequestMapping("/kafka/streams")
    public String sendMessageStreams(){
        kafkaTemplate.send("StreamTopic","key1","你好1");
        return "success";
    }
}
